﻿using RStudio.UIFramwork.Utils;
using UIFramwork.Factory;
using UnityEngine;


namespace RStudio.UIFramwork
{
    /// <summary>
    /// 处理器|区域退出
    /// </summary>
    public class HandlerUseAreaQuit : IUIHandler, IUIAcquisition
    {
        public IUIHandler Next { get; set; }

        public void Handle(UIBase uiBase)
        {
            if (uiBase.UseAreaQuit)
            {
                if (IsAcquisition)
                {
                    GameObject target = UIComponentFactoryUtil.GetAreaQuit();
                    target.transform.SetParent(uiBase.transform);
                    LayoutUtil.SetSibling(target.transform, 0);
                }
                else
                {
                    UIComponentFactoryUtil.Recycle<UIAreaQuit>(uiBase.transform.GetComponentInChildren<UIAreaQuit>().gameObject);
                }
            }

            Next?.Handle(uiBase);
        }




        public bool IsAcquisition { get; private set; }
        public HandlerUseAreaQuit(bool isAcquisition = true)
        {
            this.IsAcquisition = isAcquisition;
        }
    }
}
